#ifndef LS_WebsocketClient_H
#define LS_WebsocketClient_H

#include "common.h"
#include <string>
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>

using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;

class WebsocketClient
{
public:
    typedef std::function<void(std::string)> receive_handler;

    typedef websocketpp::client<websocketpp::config::asio_client> client;
    typedef websocketpp::config::asio_client::message_type::ptr message_ptr; 

private:
    bool is_connect = false;
    void on_open();
    void on_close();
    std::string uri; 

    client echo_client;
    client::connection_ptr con;

    receive_handler m_receive_handler;

    void on_message(websocketpp::connection_hdl hdl, message_ptr msg);
public:
    WebsocketClient();
    ~WebsocketClient();

    void set_receive_handler(receive_handler h) {
        m_receive_handler = h;
    }

    int open(std::string);
    int close();
    bool get_is_connect() { return is_connect; };
    std::string get_uri() { return uri; };
    //向服务端发二进制消息
    int sendBinaryData(Data, size_t);
    int sendTextData(char *);
};

#endif